#!usr/bin/python
# -*= coding: UTF-8 -*-
import urllib.request
import urllib.parse
import json

content = input('请输入需要翻译的内容：')
'''
http://fanyi.youdao.com/translate_o?smartresult=dict&smartresult=rule&smartresult=ugc&sessionFrom=http://www.youdao.com/

表单data
i: 爬虫的自我x
from: AUTO
to: AUTO
smartresult: dict
client: fanyideskweb
salt: 15823378233800
sign: 4bd57b7a293cdf19f241de8f3cef2c01
ts: 1582337823380
bv: 9f562c65894a46aa49489fa90fa1187f
doctype: json
version: 2.1
keyfrom: fanyi.web
action: FY_BY_REALTlME
'''
#url = 'http://fanyi.youdao.com/translate_o?smartresult=dict&smartresult=rule'
url = 'http://fanyi.youdao.com/translate?smartresult=dict&smartresult=rule'
data = {}
data['type'] = 'AUTO'
data['i'] = 'I love php.cn'
data['xmlVersion'] = '1.6'
data['keyfrom'] = 'fanyi.web'
data['ue'] = 'UTF-8'
data['typeResult'] = 'true'
data = urllib.parse.urlencode('utf-8')

response = urllib.request.urlopen(url, data)

html = response.read().decode('utf-8')
#print(html)
target = json.loads(html)
print('翻译结果：%s' % (target['translateResult'][0][0]['tgt']))




